 var id = getvl("id");
  var  pifa=0;
 $(function(){
 	if(id!=''){
 		 $.ajax({
        url: urlcore + "/api/goods/selectColorAndSizeByGoodsId?goodsId="+id,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					var da=data.data.goods;
	  var shangping='<input type="text" style="display: none;" value="'+da.id+'" id="goodsIds">'+
					'<dt>'+
'			<img onerror="errorImg(this)" src="'+da.coverUrl+'" />'+
'		</dt>'+
'		<dd>'+
'			<p>'+da.goodsTitle+'</p>'+ //全场满500或15件可混批
'			<ul class="clearfix" style="margin-top:20px">'+
'				<li>'+
'					<span>'+da.tradeNumber+'件</span>'+
'					<h6>&yen;'+da.tradePrice.toFixed(2)+'</h6>'+
'         <input type="hidden" id="pifajiage" value="'+da.tradePrice.toFixed(2)+'">'+

'				</li>'+
'				<li>'+
'					<span></span>'+//'+da.packNumber+'-'+da.tradeNumber+'件
'					<h6></h6>'+ //&yen;'+da.tradePrice+'
'				</li>'+
'				<li>'+
'					<span>'+da.packNumber+'件</span>'+
'					<h6>&yen;'+da.packPrice.toFixed(2)+'</h6>'+
'                   <input type="hidden" id="jiage"  value="'+da.packPrice.toFixed(2)+'">'+
'				</li>'+
'			</ul>'+
'		</dd>';	
  pifa=da.packNumber;
                  $("#shangping").append(shangping);
                  $.each(data.data.list, function(y,n) {
                var  goodsguige='<li class="clearfix" id="guige">'+
'			<span>'+n.colour.colourName+'</span>'+
'           <span></span>'+
'			<span>'+n.size.sizeName+'</span>'+
'			<div class="lt-rt">'+
'<input type="text" style="display: none;" id="kuchunid" value="'+n.id+'">'+
'<input type="text" id="shopIds"  style="display: none;" value="'+n.shopId+'">'+
'             <input type="text" style="display: none;" value="'+n.leftNum+'">'+
'             <input type="button" class="minus" onclick="jianhao(this)"  value="-">' +
'             <input type="text" class="zhizhi" id="num" onchange="wenbenkuang(this)" class="result" value="0">' +
'             <input type="button" class="add" onclick="jiahao(this)" value="+">' +
'		    </div>'+
'<input type="text" style="display: none;" id="kuchuanss" value="'+n.leftNum+'">'+
'		    <em>库存'+n.leftNum+'件</em>'+
'		</li>';
                $("#goodsguige").append(goodsguige);
                  });
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});
		
 	}
 });





function qutianjia(){
	// console.log(uuuuid)
  if(uuuuid!=''){
	     var myStocks =[];
	     var myshook="";
	     var sn=0;
	     	var jianshu=0;
	     myshook+='[';
           $("input[class='zhizhi']").each(function () {
           	  	 if(jianshu>=pifa){
           jine=$("#pifajiage").val();
           	 }else{
           	 	 jine=$("#jiage").val();
           	 }
           	    if(parseInt($(this).val())!=0){
           	    	sn++;
                   var pa=parseInt($(this).val());
                   var guige=$(this).prev().prev().prev().prev().val();//规格id
                
                   if(sn==1){
                   	 myshook+='{"id":'+guige+',"saleNum":'+pa+',"goodsType":'+1+',"zbDirectSeedingId":'+null+',"packRate":'+jine+'}';
                   }else{
                   	 myshook+=',{"id":'+guige+',"saleNum":'+pa+',"goodsType":'+1+',"zbDirectSeedingId":'+null+',"packRate":'+jine+'}';
                   }
           	    }
           });
           myshook+=']';
      //  myStocks = "[{\"id\":\"394\",\"saleNum\":1},{\"id\":\"395\",\"saleNum\":1},{\"id\":\"396\",\"saleNum\":1}]"
 	
 	   if(myshook.length<10){
 	   	alert("未添加商品够买数量");
 	   }else{
 	   	  if(id!=""){
 	$.ajax({
		url: urlcore + '/api/goodsCar/updateCar2?userId='+uuuuid+"&goodsId="+id,
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
 			"myStocks": myshook,
 		}),
		dataType: "json",
		success: function(data) {
			
			if(data.success == true) {
			 window.location.href = "11.0.0gouwuche.html";
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
		
 	   	  }
 	   }
	}else{
		window.location.href = "11.0.0gouwuche.html";
		// alert("未登录/或登录超时");
		//window.location.href="1.3.0zhuce.html";
	}
}

//减号 
function jianhao(ts){
	var t=$(ts).next(); 
    if(t.val()!=''&&t.val()>0){
    	 t.val(parseInt(t.val())-1);
    }else{
    	 t.val(0);
    }
    zhijin(t.val());
}
// 加号
function jiahao(ts){
	var t=$(ts).prev();
	var shuju=$(ts).prev().prev().prev();
	//alert(shuju.val());
	if(parseInt(t.val())<parseInt(shuju.val())){
		t.val(parseInt(t.val())+1);
	}else{
		t.val(shuju.val());
	}
	zhijin(t.val());
}
//文本框 
 function wenbenkuang(ts){
   var shu=$(ts);
   	var shuju=$(ts).prev().prev().prev();
   	var results=/^(10|[1-9])$/.test(shu.val());//?"正":"非正";
   	if(parseInt(shu.val())>parseInt(shuju.val())){
   		shu.val(shuju.val());
   	}else if(parseInt(shu.val())<=0 || shu.val()==""){
   		shu.val(0);
   	}else if(results==true){
       zhijin(shu.val());
   	}else{
			zhijin(shu.val());
		}
}
function zhijin(tva){
	        var zhizhi=0;
	    $("input[class='zhizhi']").each(function () {
	            zhizhi+=parseInt($(this).val());
        });
	   $("#goodsguigess").html("");
	   $("#hejijiage").html("");
	   
    var jiage=$("#jiage").val();
    var pifajiage=$("#pifajiage").val();
    
    $("#goodsguigess").html(zhizhi);
    if(zhizhi<=pifa){
    	 $("#hejijiage").html((zhizhi*pifajiage).toFixed(2));
    }else{
    	$("#hejijiage").html((zhizhi*jiage).toFixed(2));
    }
}
